VERSION 5.00
Begin VB.Form frmTray_Basic 
   BorderStyle     =   0  'None
   Caption         =   "Form1"
   ClientHeight    =   210
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   2475
   LinkTopic       =   "Form1"
   ScaleHeight     =   210
   ScaleWidth      =   2475
   ShowInTaskbar   =   0   'False
   StartUpPosition =   2  'CenterScreen
End
Attribute VB_Name = "frmTray_Basic"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Type NOTIFYICONDATA
  cbSize As Long
  hwnd As Long
  uId As Long
  uFlags As Long
  uCallBackMessage As Long
  hIcon As Long
  szTip As String * 64
End Type

Private Const NIM_ADD = &H0 'Add to Tray
Private Const NIM_DELETE = &H2 'Remove From Tray
Private Const NIF_MESSAGE = &H1 'Message
Private Const NIF_ICON = &H2 'Icon
Private Const NIF_TIP = &H4 'TooTipText
Private Const WM_MOUSEMOVE = &H200 'On Mousemove
'Private Const WM_LBUTTONDOWN = &H201 'Left Button Down
'Private Const WM_LBUTTONUP = &H202 'Left Button Up
Private Const WM_LBUTTONDBLCLK = &H203 'Left Double Click
'Private Const WM_RBUTTONDOWN = &H204 'Right Button Down
'Private Const WM_RBUTTONUP = &H205 'Right Button Up
'Private Const WM_RBUTTONDBLCLK = &H206 'Right Double Click
'incase you're interested in others

Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
      
Private nid As NOTIFYICONDATA

Private Sub Form_Load()
  
  Me.Refresh
        
  With nid 'with system tray
    .cbSize = Len(nid)
    .hwnd = Me.hwnd
    .uId = vbNull
    .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    .uCallBackMessage = WM_MOUSEMOVE
    .hIcon = Me.Icon 'use form's icon in tray
    .szTip = "VectorNet Bot" & vbNullChar 'tooltip text
  End With
        
  Shell_NotifyIcon NIM_ADD, nid 'add to tray
  Me.Height = 0
  Me.Width = 0
   
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
Dim Action As Long
    
  If Me.ScaleMode = vbPixels Then
    Action = x
  Else
    Action = x / Screen.TwipsPerPixelX
  End If
  
  Select Case Action
    Case WM_LBUTTONDBLCLK 'Left Button Double Click
      
        '// PopupMenu mnuUnTray
        'example to popup menu instead, where you would put the code below
        
      Shell_NotifyIcon NIM_DELETE, nid
      'delete icon from tray
      Unload Me
      'unload tray form
      frmChat.Show
      'for main form
  End Select
    
End Sub
